// pages/doctor-train/doctor-train.js
const app = getApp();
Page({
  data: {
    localImg: app.globalData.staticimgUrl,
    imgBase: app.globalData.imgUrl, // 图片IP
    imgUrls: [],                    // 轮播图片
    circular: true,                 // 是否采用衔接滑动 
    indicatorDots: true,            // 是否显示画板指示点 
    autoplay: true,                 // 是否自动切换
    interval: 2500,                 // 自动切换的间隔
    duration: 500,                  // 滑动动画时长毫秒
    courses: [],
    items: [],
    academics: [],
    activities: [],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(e) {
    app.showLoading();
    this.loadBannerImg();

  },
  /**
 * 生命周期函数--监听页面显示
 */
  onShow: function () {
    this.getListData();
  },
  
  //获取轮播图片
  loadBannerImg() {
    const that = this;
    const param = {
      adType: 'train',
      type: 0
    };
    app.request({
      url: "system/advertise/getAdvertise",
      data: param,
      success: function(res) {
        that.setData({
          imgUrls: res.data
        })
      },
      fail: function(res) {
        
      }
    });
  },
  //进入轮播详情
  entryDetail(e){
    let classify;
    const type = e.currentTarget.dataset.type;
    const id = e.currentTarget.dataset.id;
    if (type == 3) { classify = 'academicId' }
    if (type == 4) { classify = 'activityId' }
    if (type == 5) { classify = 'itemId' }
    if (type == 6) { classify = 'courseId' }
    const obj = {
      id,
      classify
    }
    wx.navigateTo({
      url: '/pages/doctor-train-details/doctor-train-details?obj=' + JSON.stringify(obj)
    });
  },

  //获取列表信息
  getListData() {
    const that = this;
    app.request({
      url: 'train/home/getHomeData',
      method: "GET",
      success: function(res) {
       
        that.setData({
          courses: res.data.courses,
          items: res.data.items,
          academics: res.data.academics,
          activities: res.data.activities
        })
        wx.hideLoading();
      },
      fail: function(res) {
        
      }
    });
  },

  //点击导航/更多跳转
  navLink(e) {
    const name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/doctor-train-list/doctor-train-list?name=' + name
    });
  },
  //进入详情
  entry(e) {
    const type = e.currentTarget.dataset.type;
    const id = e.currentTarget.dataset.id;
    const classify = e.currentTarget.dataset.classify;
    const obj = {
      id,
      classify,
      type
    }
    wx.navigateTo({
      url: '/pages/doctor-train-details/doctor-train-details?obj=' + JSON.stringify(obj)
    });
  }
})